/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author         Notes
 * 2021-04-20     yaoyufan       the first version
 */
#ifndef APPLICATIONS_DATADEAL_H_
#define APPLICATIONS_DATADEAL_H_

#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
#include "mfrc.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dfs_posix.h>
#include "time.h"
#include <rtdevice.h>
#include "ssd1306.h"


#define FALSE             0
#define TRUE              1
#define MANAGE            2
#define COMMON            3
#define COMOrMAN          4
#define OPENED            1
#define CLOSED            0

#define LED_R "PE.1"
#define LED_G "PE.4"
#define LED_B "PA.2"

#define ON  PIN_LOW
#define OFF PIN_HIGH

typedef struct
{
    uint8_t MangeCardNumber;
    uint8_t ComCardNumber;
    uint8_t uid_position;       //存放卡号临时位置
}CARD;
extern CARD card;

typedef struct
{
    uint8_t *time_str;//时间字符串
    uint16_t year;//年
    uint8_t month;//月
    uint8_t day;//日
    uint8_t hour;//小时
    uint8_t min;//分钟
    uint8_t sec;
}RTCTIME;
extern RTCTIME rtc_time;


extern rt_timer_t SSD1306_Timer;
extern rt_mailbox_t Uid_Mb;
extern rt_mailbox_t Result_Mb;
extern rt_device_t uart1;
void RTC_Get(void);
void Delete_AllCard(void);
uint8_t Delete_Card(uint8_t *CardSnr, uint8_t TypeName);
uint8_t Add_CommonCard(uint8_t *CardSnr);
uint8_t Add_ManageCard(uint8_t *CardSnr);
uint8_t Search_Card(uint8_t *CardSnr, uint8_t TypeName);
void Set_ComCardTime(uint8_t *temp);
void Read_ComCardTime(uint8_t *temp);
void ICCard_Deal(char *SelectedSnr);

void Str_to_Hex(char *p, char Snr[]);
void timeout_callback(void *parameter);
void Mfrc_Thread_Entry(void *parameter);
void CardDeal_Thread_Entry(void *parameter);
void SSD1306_Thread_Entry(void *parameter);
void Uart1_Thread_Entry(void *parameter);
#endif /* APPLICATIONS_DATADEAL_H_ */
